package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.DataCleanManager;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

/**
 * Created by Administrator on 2017/1/17.
 */

public class SetUpActivity extends BaseActivity implements View.OnClickListener {
    private Activity mActivity;
    private ImageView img_back;
    private RelativeLayout rly_clear_cache, rly_modify_password, rly_my_accountnum;
    private TextView tv_cache_size;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setup);
        mActivity = this;
        init();
//        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);

    }

    private void init() {
        img_back = (ImageView) mActivity.findViewById(R.id.img_back);
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tv_cache_size = (TextView) mActivity.findViewById(R.id.tv_cache_size);

        rly_clear_cache = (RelativeLayout) mActivity.findViewById(R.id.rly_clear_cache);
        rly_modify_password = (RelativeLayout) mActivity.findViewById(R.id.rly_modify_password);
        rly_my_accountnum = (RelativeLayout) mActivity.findViewById(R.id.rly_my_accountnum);

        rly_clear_cache.setOnClickListener(this);
        rly_modify_password.setOnClickListener(this);
        rly_my_accountnum.setOnClickListener(this);
        try {
            tv_cache_size.setText(DataCleanManager.getTotalCacheSize(mActivity));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rly_clear_cache:
                initClearDialog();
                break;
            case R.id.rly_modify_password:
                startActivity(new Intent(mActivity, Modify_Password.class));

                break;
            case R.id.rly_my_accountnum:
                startActivity(new Intent(mActivity, MyAccountActivity.class));

                break;
        }

    }

    private void initClearDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setMessage("确定清除缓存吗？");
        builder.setTitle("提示");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                DataCleanManager.clearAllCache(mActivity);
                tv_cache_size.setText("0K");
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.create().show();
    }
}
